package com.ccx.demo.utils;

import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
public class SSHUtils {

    private RemoteShellExecutor remoteShellExecutor=null;


    String ip="10.0.20.45";
    String username="root";
    String password="ccx425273580";

    public ArrayList SendSSH(String shell) throws Exception {
        remoteShellExecutor=new RemoteShellExecutor(ip,username,password);
        ArrayList<String> exec = remoteShellExecutor.exec(shell);
        return exec;
    }


    public static void main(String[] args) throws Exception {
        SSHUtils sshUtils = new SSHUtils();
//        ArrayList last = sshUtils.SendSSH("last -f /var/log/wtmp");
        ArrayList last = sshUtils.SendSSH("lastlog");
        last.forEach(x-> System.out.println(x));
    }
}
